<?php
$appId = file_get_contents("appid.txt"); //对应自己的appId
$appSecret = file_get_contents("appsecret.txt"); //对应自己的appSecret
$wxgzhurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appId . "&secret=" . $appSecret;
$access_token_Arr = https_request($wxgzhurl);
$access_token = json_decode($access_token_Arr, true);
$ACCESS_TOKEN = $access_token['access_token']; //ACCESS_TOKEN

// 什么时候恋爱的(格式别错)
$lovestart_time=file_get_contents("lianai.txt");
$lovestart = strtotime($lovestart_time);
$end = time();
$love = ceil(($end - $lovestart) / 86400);

// 下一个生日是哪一天(格式别错)
$birthdaystart_time = file_get_contents("shengri.txt");
$birthdaystart = strtotime($birthdaystart_time);
$end = time();
$diff_days = ($birthdaystart - $end);
$birthday = (int)($diff_days/86400);
$birthday = str_replace("-", "", $birthday);

//天气接口api
$tianqi_appid=file_get_contents("tianqiappid.txt");
$tianqi_appsecret=file_get_contents("tianqiappsecret.txt");
$tianqi_city=file_get_contents("chengshi.txt");

//$tianqiurl = 'https://www.yiketianqi.com/free/day?appid=95943915&appsecret=5KNSKu9y&unescape=1&city=武汉'; //如果固定情况可以使用这个
$tianqiurl = 'https://www.yiketianqi.com/free/day?appid='.$tianqi_appid.'&appsecret='.$tianqi_appsecret.'&unescape=1&city='.$tianqi_city; //修改为自己的
//var_dump($tianqiurl);die;
$tianqiapi = https_request($tianqiurl);
$tianqi = json_decode($tianqiapi, true);

//情话接口
$qinghuatoken=file_get_contents("qinghuatoken.txt");
$qinghuaqiurl = 'https://v2.alapi.cn/api/qinghua?token='.$qinghuatoken; //修改为自己的
$qinghuaapi = https_request($qinghuaqiurl);
$qinghua = json_decode($qinghuaapi, true);


// 多个人或者多个女朋友接收————————————————————————————————————————————————————————————————————————————————————————————
$yjh = ''; //可以留空 也可以写上一句 你自己的一句话
$touser = [
    'o5gll6luXLKdt_sGiuuPKraJ_X4M',
    'o5gll6tgHMy8zzO4XBwfiCSdqKPk'
]; //你的多个女朋友的微信号或者openid
// 多个女朋友发送
foreach ($touser as $key => $value) {
    $template = array(
        'touser' => $value,
        'template_id' => '4-TaSBcooMuVPSS6HmNIxkRd9jVBZ3xcIQYt84ByP00', //模板id
        'url' => '', //跳转链接
        'data' => array(
            'first' => array(
                'value' => $yjh,
                'color' => "#000"
            ),
            'keyword1' => array(
                'value' => $tianqi['wea'],
                'color' => "#000"
            ),
            'keyword2' => array(
                'value' => $tianqi['tem_day'].' °C',
                'color' => "#000"
            ),
'keyword3' => array(
        'value' => $love . '天',
        'color' => "#000"
    ),
'keyword4' => array(
        'value' => $birthday . '天',
        'color' => "#000"
    ),
'remark' => array(
        'value' => $qinghua['data']['content'],
        'color' => "#FF0000"
    ),
)
);
$template = json_encode($template);
$url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $ACCESS_TOKEN;
$res = https_request($url, $template);
$res = json_decode($res, true);
if ($res['errcode'] == 0) {
    echo '发送成功';
} else {
    echo '发送失败';
}
}
// 多个人或者多个女朋友接收————————————————————————————————————————————————————————————————————————————————————————————

function https_request($url, $data = null)
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)) {
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}



